﻿using Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Linguist.LexTree
{
    /// <summary>
    /// The EntryPoint table is used to manage the set of entry points into the lex tree.
    /// </summary>
    public class EntryPointTable
    {
        private Dictionary<IUnit, EntryPoint> entryPoints;
        HMMTree parent = null;

        /**
        /// Create the entry point table give the set of all possible entry point units
         *
        /// @param entryPointCollection the set of possible entry points
         */
        public EntryPointTable(List<IUnit> entryPointCollection,HMMTree _parent) 
        {
            parent = _parent;
            entryPoints = new Dictionary<IUnit, EntryPoint>();
            foreach (IUnit unit in entryPointCollection) 
            {
                entryPoints.Add(unit, new EntryPoint(unit,parent));
            }
        }


        /**
        /// Given a CI unit, return the EntryPoint object that manages the entry point for the unit
         *
        /// @param baseUnit the unit of interest (A ci unit)
        /// @return the object that manages the entry point for the unit
         */
        public EntryPoint getEntryPoint(IUnit baseUnit) 
        {
            return entryPoints[baseUnit];
        }


        /** Creates the entry point maps for all entry points. */
        public void createEntryPointMaps() 
        {
            foreach (EntryPoint ep in entryPoints.Values) 
            {
                ep.createEntryPointMap();
            }
        }


        /** Freezes the entry point table */
        public void freeze() 
        {
            foreach (EntryPoint ep in entryPoints.Values) 
            {
                ep.freeze();
            }
        }


        /** Dumps the entry point table */
        void dump() 
        {
            foreach (EntryPoint ep in entryPoints.Values) 
            {
                ep.dump();
            }
        }

    }
}
